package com.moro.lisp;

import com.moro.lisp.os.Terminal;
import com.moro.lisp.tools.FunctionPool;
import com.moro.lisp.tools.MacroPool;
import com.moro.lisp.tools.SymbolPool;


public class JLisp {//JavaLisp鐨勫ぇ绫�
	/*
	 * JavaLisp鐨勭粓绔В閲婂櫒锛屼紶鍏ava瀛楃涓茬被鍨嬬殑琛ㄨ揪寮�
	 */
	
	
	
	/*
	 * 杩欎釜瀛楁琛ㄧず褰撳墠缁堢鎵�鎹曡幏鐨勬墍鏈夌殑绗﹀彿闆嗗悎锛岀‘淇濇瘡涓�涓鍙峰彧鏈変竴涓�
	 */
	private SymbolPool symbolPool;//
	private FunctionPool functionPool;
	private MacroPool macroPool;
	
	public JLisp() {
		this.symbolPool = new SymbolPool();
		this.functionPool = new FunctionPool(this.symbolPool);
		this.macroPool = new MacroPool(this.symbolPool);
		loadLib();
	}
	
	public JLispData lisp(String expr) {//瀵笿avaLisp鏁版嵁鐨勬眰鍊硷紝浼犲叆JavaLisp鏁版嵁锛岃繑鍥濲avaLisp鏁版嵁
		this.functionPool.flush(symbolPool);
		this.macroPool.flush(symbolPool);
		return Terminal.getDataFromString(expr.trim(), symbolPool, functionPool, macroPool).eval(symbolPool, functionPool, macroPool);
	}
	public int getSymbolPoolSize() {
		return this.symbolPool.getSymbolsSize();
	}
	public int getFunctionPoolSize() {
		return this.functionPool.getFunctionPoolSize();
	}
	public int getMacroPoolSize() {
		return this.macroPool.getMacroPoolSize();
	}
	
	public boolean isLogMode() {
		return this.functionPool.isLogMode();
	}
	
	public void startDebug() {
		this.functionPool.startDebug();
	}
	
	public void closeDebug() {
		this.functionPool.closeDebug();
	}
	
	public void startDebugMode() {
		this.functionPool.startDebugMode();
	}
	
	public void closeDebugMode() {
		this.functionPool.closeDebugMode();
	}
	
	public boolean isDebugMode() {
		return this.functionPool.isLogMode();
	}
	
	public void loadLib() {
		lisp("(load '(src com moro lisp lib Common.jlisp))");
		lisp("(load '(src com moro lisp lib jlos JavaLispObjectSystem.jlisp))");
		lisp("(load '(src com moro lisp lib jlos object.jlisp))");
	}
}
